package com.hzyb.oldpack.service.impl;

import java.util.Date;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.hzyb.oldpack.dao.ShopFileDao;
import com.hzyb.oldpack.model.ShopFile;
import com.hzyb.oldpack.service.ShopFileService;
import com.hzyb.util.FileUploadUtil;
@Service
public class ShopFileServiceImpl implements ShopFileService{

	@Resource
	private ShopFileDao shopFileDao;

	//虚拟路径
	@Value("${picture.virtual.rootPath}")
	private String filepath;
	
	@Value("${hzyb.imagesPath}")
	private String system_file_path;

	@Override
	public Map<String, Object> uploadFile(byte[] is, String filename, String suffix, String filetype) {
		Map<String, Object> map=FileUploadUtil.writeFile(is, filetype, suffix,system_file_path.substring(system_file_path.indexOf("/")+1,system_file_path.length()));
		if(!map.get("status").equals("success")) {
			return map;
		}
		ShopFile shopFile=new ShopFile();
		shopFile.setFileId(map.get("file_id").toString());
		shopFile.setFileName(map.get("file_id").toString());
		shopFile.setFilePath(filepath.substring(0,filepath.lastIndexOf("/"))+"/"+filetype+"/");
		shopFile.setFileSuffix(suffix);
		shopFile.setEnterDate(new Date());
		shopFile.setRealFileName(filename+suffix);
		shopFileDao.save(shopFile);
		return map;
	}

	private FileUploadUtil FileUploadUtil() {
		// TODO Auto-generated method stub
		return null;
	}

}
